// pages/son/lend/lend_book.js
const app=getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
      navbar:['当前借阅','历史借阅'],
      currentTab: 0,
      colorList: ["rgb(240, 240, 240)", "rgb(255, 253, 235)", "rgb(226, 255, 233)", 'rgb(228, 250, 255)',"rgb(255, 235, 245)"],
      Index_color: 0,
      
      indicatorDots: true,

      book_content:[],
      book_content2: [],

     
  },
  back: function () {
    wx.navigateBack({
      url: '/pages/index/index'
    })
  },

  navbarTap: function (e) {
    this.setData({
      currentTab: e.currentTarget.dataset.idx,
    })
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
  
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
  
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    this.setData({
      currentTab: 0,

    })
    wx.setNavigationBarTitle({
      title: '掌上武大Tim'
    })
    wx.setNavigationBarColor({
      frontColor: '#ffffff',
      backgroundColor: '#00CC66',
      animation: {
        duration: 400,
        timingFunc: 'easeIn'
      }
    })
    
    if (app.globalData.lend_currentRecord==null){
      this.setData({
        book_content: [{
          "name": '书都还光啦，快去借几本吧~',
          'return_time': "",
          "location": "",
        }],
      })
    }
    if (app.globalData.lend_currentRecord != null){
      let bookContent=[];
      for (let i = 0; i < app.globalData.lend_currentRecord.length ;i++){
          let cache1 = app.globalData.lend_currentRecord[i].name+'\n';  

        let cache2 = app.globalData.lend_currentRecord[i].should_return_date.slice(0, 4) + "年" + app.globalData.lend_currentRecord[i].should_return_date.slice(4, 6) + "月" + app.globalData.lend_currentRecord[i].should_return_date.slice(6, 8) + "日" + " " + app.globalData.lend_currentRecord[i].should_return_time + '\n';

          let cache3 = app.globalData.lend_currentRecord[i].location;

          let cache = {
            "name": cache1,
            'return_time': cache2,
            "location": cache3,
          };
          bookContent.push(cache);
        }
      this.setData({
        book_content: bookContent,
      })  
    }
      if (app.globalData.lend_historyRecord == null) {
        this.setData({
          book_content2: [{
            "name": "暂无历史借阅记录",
            'return_time': "",
            "location": "",
          }],
        })
      }
      if (app.globalData.lend_historyRecord != null) {
        let bookContent2 = [];
        for (let i = 0; i < app.globalData.lend_historyRecord.length; i++) {
          let cache1 = app.globalData.lend_historyRecord[i].name + '\n';

          let cache2 = app.globalData.lend_historyRecord[i].should_return_date.slice(0, 4) + "年" + app.globalData.lend_historyRecord[i].should_return_date.slice(4, 6) + "月" + app.globalData.lend_historyRecord[i].should_return_date.slice(6, 8) + "日" + " " + app.globalData.lend_historyRecord[i].should_return_time + '\n';

          let cache3 = app.globalData.lend_historyRecord[i].location;

          let cache = {
            "name": cache1,
            'return_time': cache2,
            "location": cache3,
          };
          bookContent2.push(cache);
        }
        this.setData({
          book_content2: bookContent2,
        })  

      }



             
        
    

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
  
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
  
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
  
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
  
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
  
  }
})